home *** CD-ROM | disk | FTP | other *** search
- Path: dd.chalmers.se!news.chalmers.se!sunic!pipex!howland.reston.ans.net!darwin.sura.net!nntp.st.usm.edu!whale.st.usm.edu!not-for-mail
- From: chambles@whale.st.usm.edu (John William Chambless)
- Newsgroups: comp.lang.c
- Subject: Re: `char *a="text"` same as `char a[] = "text"` ??
- Date: 4 Apr 1994 10:52:33 -0500
- Organization: The Greys
- Lines: 73
- Message-ID: <2npd41$29pb@whale.st.usm.edu>
- References: <sstasuke.49.0004A173@wtc34a.daytonOH.ncr.com> <2midmf$5e0@dawn.mmm.com> <2mjvo8$cju@chico.staf.phil.ruu.nl> <1994Apr1.133445.6009@hns.com>
- NNTP-Posting-Host: whale.st.usm.edu
- Summary: Idiots are always right.
- Keywords: RTFM clue ANSI lvalue
-
- In article <1994Apr1.133445.6009@hns.com>, Joe Dunn <jdunn@hns.com> wrote:
- >In article <2mjvo8$cju@chico.staf.phil.ruu.nl>, hjv@phil.ruu.nl (Hendrik Jan Veenstra) writes:
- >|> First of all: there have already been several correct follow-ups to the
- >|> original question. If you're *not* sure about the correctness of your reply,
- >|> you might consider not posting it...
-
- >you should follow your own advice...
-
- ROTFL!
- The irony of your reply is classic considering how totally incorrect
- your post is.
-
- >this is absolutely wrong!! you can modify a exactly like this. only in c++
- >if you declare the pointer to a string a constant can you not modify the string
-
- Oh, really? Wow, you should immediately notify Dennis Ritchie, Brian Kernighan,
- and the ANSI comittee on C! They ALL have it wrong!
-
- >a literal string is nothing more than an array. try it:
- ^^^^^^^^
- Oh, okay. Since it works on YOUR copy of the FooBar WhizBang
- C compiler on _your_ machine, it MUST be valid code!
-
-
- > char *a = "text";
- > printf("a = %s\n",a);
- > a[1] = 'f';
- > printf("a = %s\n",a);
-
- *deep sigh*
- One more time, class--from the top:
-
- From the ANSI/ISO C Standard, 6.5.7:
-
- "...the declaration
-
- char *p = "abc";
-
- defines p with type "pointer to char" that is initialized to
- point to an object with type "array of char" with length 4 whose
- elements are initialized with a character string literal. If an
- attempt is made to use p to modify the contents of the array,
- the behaviour is undefined."
-
- The fourth paragraph of section 5.5 of K&R2 says the same thing.
-
- If you're unsure what "undefined" means, it's in Annex G of the standard,
- or you can read all about it in the comp.lang.c archives.
- >
- >sorry, no difference. in a real operating system that does not have the
- >segmented memory of DOS, code space and data space, these definitions can
- >be used interchangaebly.
-
- The OS is irrelevant.
- The fact is that some compilers will accept bletcherous code such as
- your example, but the Standard does not require them to.
-
- Run lint on your example, and see what it says.
-
- > Naturally, when DOS grows up and becomes a true 32 bit operating system
- > then we can all go back to using the statements interchangeably.
-
- Why use them interchangably?
- Most of us have already solved the problem by learning to write
- ANSI-compliant code. Code that depends on the quirks of a particular
- compiler is dangerous.
- >
- >
-
-
- --
- * Billy Chambless University of Southern Mississippi
- * "IBM is not a necessary evil. IBM is not necessary." -- Ted Nelson
-